package mf.com.controller.product;

import com.github.pagehelper.PageInfo;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import jakarta.annotation.Resource;
import mf.com.Service.Product.CategoryBrandService;
import mf.com.dto.product.CategoryBrandDto;
import mf.com.entity.product.CategoryBrand;
import mf.com.vo.common.Result;
import org.springframework.web.bind.annotation.*;

/**
 * @Author: lmf
 * @Create: 2024/4/7 21:41
 * Description:  品牌分类相关控制层
 */
@RestController
@Tag(name = "品牌分类")
@RequestMapping("/admin/product/categoryBrand")
public class CategoryBrandController {
    @Resource
    private CategoryBrandService categoryBrandService;

    //
    @Operation(summary = "分页查询品牌分页")
    @GetMapping("/{pageName}/{pageSize}")
    public Result<PageInfo<CategoryBrand>> findByPage(@PathVariable("pageSize") Integer pageSize,
                                                      @PathVariable("pageName") Integer pageName,
                                                      CategoryBrandDto categoryBrand) {
        return Result.success(categoryBrandService.findByPage(categoryBrand, pageName, pageSize));

    }

    @Operation(summary="新增品牌分类")
    @PostMapping("/save")
    public Result<Integer> save(@RequestBody CategoryBrand categoryBrand) {
        return Result.success(categoryBrandService.save(categoryBrand));
    }

    @Operation(summary="删除品牌分类")
    @GetMapping("/deleteById")
    public Result<Integer> deleteById(@RequestParam("id") Integer id) {


        return Result.success(categoryBrandService.deleteById(id));

    }


    @Operation(summary="品牌修改")
    @PostMapping("/updateById")
    public Result<Integer> updateById(@RequestBody CategoryBrand category){
        return Result.success(categoryBrandService.updateById(category));
    }
}
